package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.WorkOrderDetailsModel;
import com.czy.owner.entity.WorkOrderModel;
import com.czy.owner.utils.StringUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hedepu on 2017-08-29
 */

public class OrderPackageDetailsAdapter extends BaseRecyclerAdapter<WorkOrderDetailsModel.ServiceItemsList, OrderPackageDetailsAdapter.OrderPackageDetailsHolder> {


    private Context ctx;

    public OrderPackageDetailsAdapter(Context context, List<WorkOrderDetailsModel.ServiceItemsList> data) {
        super(context, data);
        this.ctx = context;
    }

    public void addALL(List<WorkOrderDetailsModel.ServiceItemsList> list) {
        data.clear();
        data.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(OrderPackageDetailsHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));

    }

    public List<WorkOrderDetailsModel.ServiceItemsList> getList() {
        return data;
    }

    @Override
    public OrderPackageDetailsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderPackageDetailsHolder(layoutInflater.inflate(R.layout.item_package_details_list, parent, false));
    }

    public class OrderPackageDetailsHolder extends BaseRecyclerAdapter.ViewHolder {
        @BindView(R.id.tv_card_name)
        TextView tvCardName;
        @BindView(R.id.tv_card_max_num)
        TextView tvCardMaxNum;
        @BindView(R.id.linear_card_name)
        LinearLayout linearCardName;
        @BindView(R.id.tv_project_type)
        TextView tvProjectType;
        @BindView(R.id.tv_package_name)
        TextView tvPackageName;

        public OrderPackageDetailsHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);


        }

        public void bindData(WorkOrderDetailsModel.ServiceItemsList model) {
            tvCardName.setText(model.getItemName());
            tvCardMaxNum.setText("x" + model.getCount());
            tvPackageName.setText(model.getPackageName());
            if ("goods".equals(model.getItemType())) {
                tvProjectType.setText(StringUtils.getString(model.getSpecName()));
            } else {
                tvProjectType.setText("");

            }
        }
    }

}

